package org.lex.ftp.net.find;

import java.util.Iterator;

import javax.swing.BoundedRangeModel;
import javax.swing.event.ChangeListener;

import org.lex.net.ftp.FTPFile;
import org.lex.net.ftp.IFTPClient;
import org.lex.net.ftp.IFTPFile;
import org.lex.utils.tree.DFS;


public class FTPFileIterator implements Iterator<IFTPFile>, BoundedRangeModel {
	public static DFS createDFS(final IFTPClient ftp, final String path) {
		return new DFS(createRootNode(ftp, path));
	}

	public static FTPFileNode createRootNode(IFTPClient ftp, String path) {
		return new FTPFileNode(ftp, FTPFile.newFile(path, "", true));
	}

	private final DFS dfs;

	public FTPFileIterator(IFTPClient ftp, String path) {
		dfs = createDFS(ftp, path);
	}

	/***************************************************************************
	 * Iterator<IFTPFile>
	 **************************************************************************/
	public boolean hasNext() {
		return dfs.hasNext();
	}

	public IFTPFile next() {
		return ((FTPFileNode) dfs.next()).getData();
	}

	public void remove() {
		throw new UnsupportedOperationException("remove");
	}

	/***************************************************************************
	 * BoundedRangeModel
	 **************************************************************************/
	public void addChangeListener(ChangeListener l) {
		dfs.addChangeListener(l);
	}

	public int getExtent() {
		return dfs.getExtent();
	}

	public int getMaximum() {
		return dfs.getMaximum();
	}

	public int getMinimum() {
		return dfs.getMinimum();
	}

	public int getValue() {
		return dfs.getValue();
	}

	public boolean getValueIsAdjusting() {
		return dfs.getValueIsAdjusting();
	}

	public void removeChangeListener(ChangeListener l) {
		dfs.removeChangeListener(l);
	}

	public void setExtent(int n) {
		dfs.setExtent(n);
	}

	public void setMaximum(int n) {
		dfs.setMaximum(n);
	}

	public void setMinimum(int n) {
		dfs.setMinimum(n);
	}

	public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) {
		dfs.setRangeProperties(newValue, newExtent, newMin, newMax, adjusting);
	}

	public void setValue(int n) {
		dfs.setValue(n);
	}

	public void setValueIsAdjusting(boolean b) {
		dfs.setValueIsAdjusting(b);
	}

	@Override
	public String toString() {
		return dfs.toString();
	}
}
